import { Router, useRouter } from 'vue-router'

export function isInfoPermission(record: any) {
  const bizDataJson = record.bizDataJson || record.bizData
  switch (record.type) {
    case 1:
      return bizDataJson.orderType === 1 ? 'svms:order:short-order' : 'svms:order:long-order'
    case 2:
      return 'svms:business:channel:order-sync'
    case 3:
      return bizDataJson.orderType === 1 ? 'svms:order:short-order' : 'svms:order:long-order'
    case 4:
      return bizDataJson.orderType === 1 ? 'svms:order:short-order' : 'svms:order:long-order'
    case 5:
      return bizDataJson.orderType === 1 ? 'svms:order:short-order' : 'svms:order:long-order'
    case 6:
      return bizDataJson.orderType === 1 ? 'svms:order:short-order' : 'svms:order:long-order'
    case 7:
      return bizDataJson.orderType === 1 ? 'svms:order:short-order' : 'svms:order:long-order'
    case 8:
      return bizDataJson.orderType === 1 ? 'svms:order:short-order' : 'svms:order:long-order'
    case 11:
      return 'svms:index:operation:caroilview'
    case 12:
      return 'svms:index:operation:mileageview'
    case 13:
      return 'svms:index:operation:insureCompulsoryview'
    case 14:
      return 'svms:index:operation:insureBusinessview'
    case 15:
      return 'svms:index:operation:imaintenanceWaitview'
    case 16:
      return 'svms:index:operation:inspectionWaitview'
    case 17:
      return 'svms:asstes:operation:car-repair'
    case 18:
      return 'svms:asstes:operation:car-violation'
    case 19:
    case 35:
    case 36:
    case 37:
    case 38:
      return bizDataJson.orderType === 1 ? 'svms:order:short-order' : 'svms:order:long-order'
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    case 25:
      return 'svms:workOrder:workOrder:order'
    case 26:
    case 27:
    case 28:
    case 29:
      return 'svms:business:operate-cost'
    case 30:
      return 'svms:business:channel:inventory-sync'
    case 33:
      return 'svms:business:channel:sync-ota-price'
    case 34:
      return 'svms:finance:tripartitePayment'
  }
}
export function toInfoDetail(router: Router, val: any, callback?: () => void) {
  console.log('🐳 > toInfoDetail > val:', val)
  const type = val.type
  const bizDataJson = val.bizDataJson || val.bizData

  function router2Path(path: string) {
    router.push('/redirect' + path)
    callback && callback()
  }

  // 1.新订单提醒
  const pushNewOrder = (bizDataJson: any) => {
    if (bizDataJson.batch == 0) {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?orderNo=${bizDataJson.code}`)
    } else {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?id=10,100`)
    }
  }
  // 2.OTA订单同步成功/失败
  const pushOTA = (bizDataJson: any) => {
    router2Path(
      `/business/channel/order-sync?startTime=${bizDataJson.startTime}&sourceId=${bizDataJson.sourceId}&syncStaffId=${
        bizDataJson.syncStaffId || ''
      }&otaType=${bizDataJson.otaType}`
    )
  }
  // 3.待排车通知
  const pushOrder10 = (bizDataJson: any) => {
    if (bizDataJson.batch == 0) {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?orderNo=${bizDataJson.code}`)
    } else {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?id=10`)
    }
  }
  // 4.即将交车通知
  const pushGiveCar = (bizDataJson: any) => {
    if (bizDataJson.batch == 0) {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?orderNo=${bizDataJson.code}`)
    } else {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?name=今日交车`)
    }
  }
  // 5.即将还车通知
  const pushReturnToday = (bizDataJson: any) => {
    if (bizDataJson.batch == 0) {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?orderNo=${bizDataJson.code}`)
    } else {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?name=今日还车`)
    }
  }
  // 6.逾期未交通知
  const pushGiveOverdue = (bizDataJson: any) => {
    if (bizDataJson.batch == 0) {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?orderNo=${bizDataJson.code}`)
    } else {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?name=逾期未交`)
    }
  }
  // 7.逾期未还通知
  const pushReturnOverdue = (bizDataJson: any) => {
    if (bizDataJson.batch == 0) {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?orderNo=${bizDataJson.code}`)
    } else {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?name=逾期未还`)
    }
  }
  // 8.电子合同未签署
  const pushSigningNum = (bizDataJson: any) => {
    if (bizDataJson.batch == 0) {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?orderNo=${bizDataJson.code}`)
    } else {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?name=合同签署中(付费版)`)
    }
  }
  // 11,12,13,14,15,16 跳转首页待办事项
  const pushIndexTodo = (typeName: any) => {
    const name = typeName.split('通知').join('')
    router2Path(`/index/to-do?label=${name}`)
  }
  // 17.待维修车辆
  const pushRepair = () => {
    router2Path(`/assets/operation/car-repair?status=0`)
  }
  // 18.待处理违章
  const pushViolation = () => {
    router2Path(`/assets/violation/car-violation?id=0`)
  }
  // 19.车辆冲突
  const pushCarConflict = (bizDataJson: any) => {
    router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?name=车辆冲突`)
  }
  // 20.待指派负责人
  const pushAssignOwner = (bizDataJson: any) => {
    if (bizDataJson.batch == 0) {
      router2Path(`/business/work-order/order?workOrderCode=${bizDataJson.code}`)
    } else {
      router2Path(`/business/work-order/order?statusList=1`)
    }
  }
  // 21.待接单 22.待审核改派 23.申请改派结果通知
  const pushWorkOrder = (bizDataJson: any) => {
    router2Path(`/business/work-order/order?workOrderCode=${bizDataJson.code}`)
  }
  // 24. 待处理工单
  const pushWorkOrderDeal = (bizDataJson: any) => {
    if (bizDataJson.batch == 0) {
      router2Path(`/business/work-order/order?workOrderCode=${bizDataJson.code}`)
    } else {
      router2Path(`/business/work-order/order?statusList=3`)
    }
  }
  // 25.负责人拒绝
  const pushWorkOrderRefuse = (bizDataJson: any) => {
    router2Path(`/business/work-order/order?workOrderCode=${bizDataJson.code}`)
  }
  // 26.审批待处理通知 27.审批处理结果通知 28.支出单待付款通知 29.支出单完成付款通知
  const pushApproval = (bizDataJson: any) => {
    router2Path(`/business/operate-cost?code=${bizDataJson.code}`)
  }

  // 30.库存同步失败
  const pushStockSync = (bizDataJson: any) => {
    router2Path(
      `/business/channel/inventory-sync?sourceId=${bizDataJson.sourceId}&accountId=${bizDataJson.accountId}&syncStatus=0&endTime=${bizDataJson.endTime}`
    )
  }
  // 33.车型价格反写结果
  const pushOtaPriceSync = () => {
    router2Path(`/business/channel/sync-ota-price`)
  }

  // 34. 三方账单支付结果通知
  const pushTripartitePayment = (bizDataJson: any) => {
    console.log('pushTripartitePayment', bizDataJson)

    router2Path(`/finance/tripartitePayment?code=${bizDataJson.code}`)
  }

  // 35 36 37 38 通知
  const pushNotice = (val: any) => {
    const bizDataJson = val.bizDataJson || val.bizData
    if (bizDataJson.batch == 0) {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?orderNo=${bizDataJson.code}`)
    } else {
      router2Path(`/order/${bizDataJson.orderType == 2 ? 'long-order' : 'short-order'}?name=${val.title.replace(/通知$/, '')}`)
    }
  }

  if (type == 1) {
    pushNewOrder(bizDataJson)
  } else if (type == 2) {
    pushOTA(bizDataJson)
  } else if (type == 3) {
    pushOrder10(bizDataJson)
  } else if (type == 4) {
    pushGiveCar(bizDataJson)
  } else if (type == 5) {
    pushReturnToday(bizDataJson)
  } else if (type == 6) {
    pushGiveOverdue(bizDataJson)
  } else if (type == 7) {
    pushReturnOverdue(bizDataJson)
  } else if (type == 8) {
    pushSigningNum(bizDataJson)
  } else if (type == 9) {
  } else if (type == 10) {
  } else if (type == 11 || type == 12 || type == 13 || type == 14 || type == 15 || type == 16) {
    pushIndexTodo(val.title)
  } else if (type == 17) {
    pushRepair()
  } else if (type == 18) {
    pushViolation()
  } else if (type == 19) {
    pushCarConflict(bizDataJson)
  } else if (type == 20) {
    pushAssignOwner(bizDataJson)
  } else if (type == 21 || type == 22 || type == 23) {
    pushWorkOrder(bizDataJson)
  } else if (type == 24) {
    pushWorkOrderDeal(bizDataJson)
  } else if (type == 25) {
    pushWorkOrderRefuse(bizDataJson)
  } else if (type === 26 || type === 27 || type === 28 || type === 29) {
    pushApproval(bizDataJson)
  } else if (type === 30) {
    pushStockSync(bizDataJson)
  } else if (type === 33) {
    pushOtaPriceSync()
  } else if (type === 34) {
    pushTripartitePayment(bizDataJson)
  } else if (type === 35 || type === 36 || type === 37 || type === 38) {
    pushNotice(val)
  }
}

const useInfoPermission = (router_i?: Router) => {
  const router = router_i || useRouter()

  return {
    isInfoPermission,
    toInfoDetail: (v: any, callback?: () => void) => {
      toInfoDetail(router, v, callback)
    },
  }
}

export default useInfoPermission
